using System;
using System.Data;
using System.Configuration;
using CodeWork.Library.Data;
using System.Data.Common;
using System.Collections.Generic;
using System.Data.SqlTypes;
using CodeWork.Library;
using System.Text;
using System.Data.SqlClient;

/// <summary>
/// ORM object that maps to tbl_sitesettings
/// </summary>
namespace CodeWork.DAL.DataContainers.SqlServer
{
    public class Sitesettings : SqlServerDAO
    {
        /// <summary>
        /// Self table parameters
        /// </summary>
        private int _id;
		private string _settingName;
		private string _adminEmail;
		private string _securityKey;
		private string _supportEmail;
		private string _smtpHost;
		private string _smtpUsername;
		private string _smtpPassword;
		private int _smtpPort;
		private bool _smtpUseSsl;
		private string _siteName;
		private string _defaultTheme;
		private int _defaultTimeZone;
		private int _defaultUserroleId;
		private string _currentDomain;

        /// <summary>
        /// Foriegn key parameters
        /// </summary>
        

        /// <summary>
        /// Self table properties
        /// </summary>
		public int Id
		{
			get { return this._id; }
			set { this._id = value; }
		}

		public string SettingName
		{
			get { return this._settingName; }
			set { this._settingName = value; }
		}

		public string AdminEmail
		{
			get { return this._adminEmail; }
			set { this._adminEmail = value; }
		}

		public string SecurityKey
		{
			get { return this._securityKey; }
			set { this._securityKey = value; }
		}

		public string SupportEmail
		{
			get { return this._supportEmail; }
			set { this._supportEmail = value; }
		}

		public string SmtpHost
		{
			get { return this._smtpHost; }
			set { this._smtpHost = value; }
		}

		public string SmtpUsername
		{
			get { return this._smtpUsername; }
			set { this._smtpUsername = value; }
		}

		public string SmtpPassword
		{
			get { return this._smtpPassword; }
			set { this._smtpPassword = value; }
		}

		public int SmtpPort
		{
			get { return this._smtpPort; }
			set { this._smtpPort = value; }
		}

		public bool SmtpUseSsl
		{
			get { return this._smtpUseSsl; }
			set { this._smtpUseSsl = value; }
		}

		public string SiteName
		{
			get { return this._siteName; }
			set { this._siteName = value; }
		}

		public string DefaultTheme
		{
			get { return this._defaultTheme; }
			set { this._defaultTheme = value; }
		}

		public int DefaultTimeZone
		{
			get { return this._defaultTimeZone; }
			set { this._defaultTimeZone = value; }
		}

		public int DefaultUserroleId
		{
			get { return this._defaultUserroleId; }
			set { this._defaultUserroleId = value; }
		}

		public string CurrentDomain
		{
			get { return this._currentDomain; }
			set { this._currentDomain = value; }
		}
		
        /// <summary>
        /// Foreign key properties, loaded on demand only
        /// </summary>
        

        /// <summary>
        /// Empty Constructor
        /// </summary>
        public Sitesettings() { }

        /// <summary>
        /// Parameterized constructor
        /// </summary>
        /// <param name="id"></param>
		/// <param name="settingName"></param>
		/// <param name="adminEmail"></param>
		/// <param name="securityKey"></param>
		/// <param name="supportEmail"></param>
		/// <param name="smtpHost"></param>
		/// <param name="smtpUsername"></param>
		/// <param name="smtpPassword"></param>
		/// <param name="smtpPort"></param>
		/// <param name="smtpUseSsl"></param>
		/// <param name="siteName"></param>
		/// <param name="defaultTheme"></param>
		/// <param name="defaultTimeZone"></param>
		/// <param name="defaultUserroleId"></param>
		/// <param name="currentDomain"></param>
        public Sitesettings
        (
            int id,
			string settingName,
			string adminEmail,
			string securityKey,
			string supportEmail,
			string smtpHost,
			string smtpUsername,
			string smtpPassword,
			int smtpPort,
			bool smtpUseSsl,
			string siteName,
			string defaultTheme,
			int defaultTimeZone,
			int defaultUserroleId,
			string currentDomain
        )
        {
            this._id = id;
			this._settingName = settingName;
			this._adminEmail = adminEmail;
			this._securityKey = securityKey;
			this._supportEmail = supportEmail;
			this._smtpHost = smtpHost;
			this._smtpUsername = smtpUsername;
			this._smtpPassword = smtpPassword;
			this._smtpPort = smtpPort;
			this._smtpUseSsl = smtpUseSsl;
			this._siteName = siteName;
			this._defaultTheme = defaultTheme;
			this._defaultTimeZone = defaultTimeZone;
			this._defaultUserroleId = defaultUserroleId;
			this._currentDomain = currentDomain;
        }

        /// <summary>
        /// Static save method. Saves the current instance in the table using the provided values using the
        /// primary key id. Expects that the Id is a primary key of an existing record in table.
        /// </summary>
        /// <param name="id"></param>
		/// <param name="settingName"></param>
		/// <param name="adminEmail"></param>
		/// <param name="securityKey"></param>
		/// <param name="supportEmail"></param>
		/// <param name="smtpHost"></param>
		/// <param name="smtpUsername"></param>
		/// <param name="smtpPassword"></param>
		/// <param name="smtpPort"></param>
		/// <param name="smtpUseSsl"></param>
		/// <param name="siteName"></param>
		/// <param name="defaultTheme"></param>
		/// <param name="defaultTimeZone"></param>
		/// <param name="defaultUserroleId"></param>
		/// <param name="currentDomain"></param>
        /// <returns>Boolean result as success or failure</returns>
        [System.ComponentModel.DataObjectMethodAttribute(System.ComponentModel.DataObjectMethodType.Update, true)]
        public static bool Save
        (
            int id,
			string settingName,
			string adminEmail,
			string securityKey,
			string supportEmail,
			string smtpHost,
			string smtpUsername,
			string smtpPassword,
			int smtpPort,
			bool smtpUseSsl,
			string siteName,
			string defaultTheme,
			int defaultTimeZone,
			int defaultUserroleId,
			string currentDomain
        )
        {
            Sitesettings sitesettings = new Sitesettings();
            sitesettings.Id = id;
			sitesettings.SettingName = settingName;
			sitesettings.AdminEmail = adminEmail;
			sitesettings.SecurityKey = securityKey;
			sitesettings.SupportEmail = supportEmail;
			sitesettings.SmtpHost = smtpHost;
			sitesettings.SmtpUsername = smtpUsername;
			sitesettings.SmtpPassword = smtpPassword;
			sitesettings.SmtpPort = smtpPort;
			sitesettings.SmtpUseSsl = smtpUseSsl;
			sitesettings.SiteName = siteName;
			sitesettings.DefaultTheme = defaultTheme;
			sitesettings.DefaultTimeZone = defaultTimeZone;
			sitesettings.DefaultUserroleId = defaultUserroleId;
			sitesettings.CurrentDomain = currentDomain;

            return sitesettings.Save();
        }

        /// <summary>
        /// Saves the current instance and returns result
        /// </summary>
        /// <returns>Boolean result as success or failure</returns>
        public override bool Save()
        {
			SqlCommand command = (SqlCommand)CreateCommand();
			
            AddCommandParameter(command, "@ReturnValue", SqlDbType.Int, 0, ParameterDirection.ReturnValue, null);
            AddCommandParameter(command, "@Id", SqlDbType.Int, 0, ParameterDirection.Input, Id);
			AddCommandParameter(command, "@SettingName", SqlDbType.NVarChar, 50, ParameterDirection.Input, SettingName);
			AddCommandParameter(command, "@AdminEmail", SqlDbType.NVarChar, 50, ParameterDirection.Input, AdminEmail);
			AddCommandParameter(command, "@SecurityKey", SqlDbType.NVarChar, 50, ParameterDirection.Input, SecurityKey);
			AddCommandParameter(command, "@SupportEmail", SqlDbType.NVarChar, 50, ParameterDirection.Input, SupportEmail);
			AddCommandParameter(command, "@SmtpHost", SqlDbType.NVarChar, 50, ParameterDirection.Input, SmtpHost);
			AddCommandParameter(command, "@SmtpUsername", SqlDbType.NVarChar, 50, ParameterDirection.Input, SmtpUsername);
			AddCommandParameter(command, "@SmtpPassword", SqlDbType.NVarChar, 50, ParameterDirection.Input, SmtpPassword);
			AddCommandParameter(command, "@SmtpPort", SqlDbType.Int, 0, ParameterDirection.Input, SmtpPort);
			AddCommandParameter(command, "@SmtpUseSsl", SqlDbType.Bit, 0, ParameterDirection.Input, SmtpUseSsl);
			AddCommandParameter(command, "@SiteName", SqlDbType.NVarChar, 50, ParameterDirection.Input, SiteName);
			AddCommandParameter(command, "@DefaultTheme", SqlDbType.NVarChar, 50, ParameterDirection.Input, DefaultTheme);
			AddCommandParameter(command, "@DefaultTimeZone", SqlDbType.Int, 0, ParameterDirection.Input, DefaultTimeZone);
			AddCommandParameter(command, "@DefaultUserroleId", SqlDbType.Int, 0, ParameterDirection.Input, DefaultUserroleId);
			AddCommandParameter(command, "@CurrentDomain", SqlDbType.NVarChar, 50, ParameterDirection.Input, CurrentDomain);

            SetCommandType(command, CommandType.StoredProcedure, StoreProcedureName.Sp_Sitesettings_Save.ToString());

            int returnValue = (int)GetOneData(command);
            return (returnValue == 0 ? false : true);
        }

        /// <summary>
        /// Saves the current instance based on provided conditions. This method assumes that
        /// conditions are provided in correct order and in proper format.
        /// </summary>
        /// <param name="conditions">Custom condition based on which to match data</param>
        /// <returns>Boolean result as success or failure</returns>
        [System.ComponentModel.DataObjectMethodAttribute(System.ComponentModel.DataObjectMethodType.Update, true)]
        public bool Save(List<Condition> conditions)
        {
			SqlCommand command = (SqlCommand)CreateCommand();
			
            PrepareConditionalParameters(command, conditions);

            AddCommandParameter(command, "@NewSettingName", SqlDbType.NVarChar, 50, ParameterDirection.Input, SettingName);
			AddCommandParameter(command, "@NewAdminEmail", SqlDbType.NVarChar, 50, ParameterDirection.Input, AdminEmail);
			AddCommandParameter(command, "@NewSecurityKey", SqlDbType.NVarChar, 50, ParameterDirection.Input, SecurityKey);
			AddCommandParameter(command, "@NewSupportEmail", SqlDbType.NVarChar, 50, ParameterDirection.Input, SupportEmail);
			AddCommandParameter(command, "@NewSmtpHost", SqlDbType.NVarChar, 50, ParameterDirection.Input, SmtpHost);
			AddCommandParameter(command, "@NewSmtpUsername", SqlDbType.NVarChar, 50, ParameterDirection.Input, SmtpUsername);
			AddCommandParameter(command, "@NewSmtpPassword", SqlDbType.NVarChar, 50, ParameterDirection.Input, SmtpPassword);
			AddCommandParameter(command, "@NewSmtpPort", SqlDbType.Int, 0, ParameterDirection.Input, SmtpPort);
			AddCommandParameter(command, "@NewSmtpUseSsl", SqlDbType.Bit, 0, ParameterDirection.Input, SmtpUseSsl);
			AddCommandParameter(command, "@NewSiteName", SqlDbType.NVarChar, 50, ParameterDirection.Input, SiteName);
			AddCommandParameter(command, "@NewDefaultTheme", SqlDbType.NVarChar, 50, ParameterDirection.Input, DefaultTheme);
			AddCommandParameter(command, "@NewDefaultTimeZone", SqlDbType.Int, 0, ParameterDirection.Input, DefaultTimeZone);
			AddCommandParameter(command, "@NewDefaultUserroleId", SqlDbType.Int, 0, ParameterDirection.Input, DefaultUserroleId);
			AddCommandParameter(command, "@NewCurrentDomain", SqlDbType.NVarChar, 50, ParameterDirection.Input, CurrentDomain);

            SetCommandType(command, CommandType.StoredProcedure, StoreProcedureName.Sp_Sitesettings_SaveConditional.ToString());

            int returnValue = (int)GetOneData(command);
            return (returnValue == 0 ? false : true);
        }

        /// <summary>
        /// Static creational method. This method actually adds a new entry in the table with
        /// the provided information.
        /// </summary>
        /// <param name="settingName"></param>
		/// <param name="adminEmail"></param>
		/// <param name="securityKey"></param>
		/// <param name="supportEmail"></param>
		/// <param name="smtpHost"></param>
		/// <param name="smtpUsername"></param>
		/// <param name="smtpPassword"></param>
		/// <param name="smtpPort"></param>
		/// <param name="smtpUseSsl"></param>
		/// <param name="siteName"></param>
		/// <param name="defaultTheme"></param>
		/// <param name="defaultTimeZone"></param>
		/// <param name="defaultUserroleId"></param>
		/// <param name="currentDomain"></param>
        /// <returns>Instance of the created object</returns>
        [System.ComponentModel.DataObjectMethodAttribute(System.ComponentModel.DataObjectMethodType.Update, true)]
        public static Sitesettings Create
        (
            string settingName,
			string adminEmail,
			string securityKey,
			string supportEmail,
			string smtpHost,
			string smtpUsername,
			string smtpPassword,
			int smtpPort,
			bool smtpUseSsl,
			string siteName,
			string defaultTheme,
			int defaultTimeZone,
			int defaultUserroleId,
			string currentDomain
        )
        {
            Sitesettings sitesettings = new Sitesettings();
            sitesettings.SettingName = settingName;
			sitesettings.AdminEmail = adminEmail;
			sitesettings.SecurityKey = securityKey;
			sitesettings.SupportEmail = supportEmail;
			sitesettings.SmtpHost = smtpHost;
			sitesettings.SmtpUsername = smtpUsername;
			sitesettings.SmtpPassword = smtpPassword;
			sitesettings.SmtpPort = smtpPort;
			sitesettings.SmtpUseSsl = smtpUseSsl;
			sitesettings.SiteName = siteName;
			sitesettings.DefaultTheme = defaultTheme;
			sitesettings.DefaultTimeZone = defaultTimeZone;
			sitesettings.DefaultUserroleId = defaultUserroleId;
			sitesettings.CurrentDomain = currentDomain;

            return (sitesettings.Create() ? sitesettings : null);
        }

        /// <summary>
        /// Instance creational method. Inserts the current object as a new entry in table.
        /// </summary>
        /// <returns>Boolean result as success or failure</returns>
        public override bool Create()
        {
			SqlCommand command = (SqlCommand)CreateCommand();
			
            AddCommandParameter(command, "@ReturnValue", SqlDbType.Int, 0, ParameterDirection.ReturnValue, null);
            AddCommandParameter(command, "@SettingName", SqlDbType.NVarChar, 50, ParameterDirection.Input, SettingName);
			AddCommandParameter(command, "@AdminEmail", SqlDbType.NVarChar, 50, ParameterDirection.Input, AdminEmail);
			AddCommandParameter(command, "@SecurityKey", SqlDbType.NVarChar, 50, ParameterDirection.Input, SecurityKey);
			AddCommandParameter(command, "@SupportEmail", SqlDbType.NVarChar, 50, ParameterDirection.Input, SupportEmail);
			AddCommandParameter(command, "@SmtpHost", SqlDbType.NVarChar, 50, ParameterDirection.Input, SmtpHost);
			AddCommandParameter(command, "@SmtpUsername", SqlDbType.NVarChar, 50, ParameterDirection.Input, SmtpUsername);
			AddCommandParameter(command, "@SmtpPassword", SqlDbType.NVarChar, 50, ParameterDirection.Input, SmtpPassword);
			AddCommandParameter(command, "@SmtpPort", SqlDbType.Int, 0, ParameterDirection.Input, SmtpPort);
			AddCommandParameter(command, "@SmtpUseSsl", SqlDbType.Bit, 0, ParameterDirection.Input, SmtpUseSsl);
			AddCommandParameter(command, "@SiteName", SqlDbType.NVarChar, 50, ParameterDirection.Input, SiteName);
			AddCommandParameter(command, "@DefaultTheme", SqlDbType.NVarChar, 50, ParameterDirection.Input, DefaultTheme);
			AddCommandParameter(command, "@DefaultTimeZone", SqlDbType.Int, 0, ParameterDirection.Input, DefaultTimeZone);
			AddCommandParameter(command, "@DefaultUserroleId", SqlDbType.Int, 0, ParameterDirection.Input, DefaultUserroleId);
			AddCommandParameter(command, "@CurrentDomain", SqlDbType.NVarChar, 50, ParameterDirection.Input, CurrentDomain);

            SetCommandType(command, CommandType.StoredProcedure, StoreProcedureName.Sp_Sitesettings_Create.ToString());

            Id = (int)GetOneData(command);
            return (Id == 0 ? false : true);
        }

        /// <summary>
        /// Static deletion method. Deletes a record from table using the provided primary key id.
        /// </summary>
        /// <param name="id">Primary key</param>
        /// <returns>Boolean result as success or failure</returns>
        [System.ComponentModel.DataObjectMethodAttribute(System.ComponentModel.DataObjectMethodType.Delete, true)]
        public static bool Delete(int id)
        {
            Sitesettings sitesettings = new Sitesettings();
            sitesettings.Id = id;

            return sitesettings.Delete();
        }

        /// <summary>
        /// Static deletion method. Deletes a list record from table using the provided primary keys id.
        /// </summary>
        /// <param name="ids">List of primarky key id</param>
        /// <returns>Boolean result as success or failure</returns>
        [System.ComponentModel.DataObjectMethodAttribute(System.ComponentModel.DataObjectMethodType.Delete, true)]
        public static bool Delete(List<int> ids)
        {
            string csvIds = Utility.MakeCSV(ids);

            Sitesettings sitesettings = new Sitesettings();

            return sitesettings.Delete(csvIds);
        }

        /// <summary>
        /// Static deletion method. Deletes records from table using provided conditions.
        /// </summary>
        /// <param name="conditions">Custom condition based on which to match data</param>
        /// <returns>Boolean result as success or failure</returns>
        public static bool Delete(List<Condition> conditions)
        {
            Sitesettings sitesettings = new Sitesettings();

            return sitesettings.ConditionalDelete(conditions);
        }

        /// <summary>
        /// This is helper method for conditional delete method above. Not for other general use.
        /// </summary>
        /// <param name="conditions">Custom condition based on which to match data</param>
        /// <returns>Boolean result as success or failure</returns>
        private bool ConditionalDelete(List<Condition> conditions)
        {
			SqlCommand command = (SqlCommand)CreateCommand();
			
            PrepareConditionalParameters(command, conditions);

            SetCommandType(command, CommandType.StoredProcedure, StoreProcedureName.Sp_Sitesettings_DeleteConditional.ToString());

            int returnValue = (int)GetOneData(command);
            return (returnValue == 0 ? false : true);
        }

        /// <summary>
        /// This is a helper method for multiple id delete method. Not for general use.
        /// </summary>
        /// <param name="csvIds">Comma seperated primary key values as string</param>
        /// <returns>Boolean result as success or failure</returns>
        private bool Delete(string csvIds)
        {
			SqlCommand command = (SqlCommand)CreateCommand();
			
            AddCommandParameter(command, "@ReturnValue", SqlDbType.Int, 0, ParameterDirection.ReturnValue, null);
            AddCommandParameter(command, "@Ids", SqlDbType.NVarChar, 500, ParameterDirection.Input, csvIds);

            SetCommandType(command, CommandType.StoredProcedure, StoreProcedureName.Sp_Sitesettings_DeleteMultiple.ToString());

            int returnValue = (int)GetOneData(command);
            return (returnValue == 0 ? false : true);
        }

        /// <summary>
        /// Instance deletion method. Deletes the current instance from table.
        /// </summary>
        /// <returns>Boolean result as success or failure</returns>
        public override bool Delete()
        {
			SqlCommand command = (SqlCommand)CreateCommand();
			
            AddCommandParameter(command, "@ReturnValue", SqlDbType.Int, 0, ParameterDirection.ReturnValue, null);
            AddCommandParameter(command, "@Id", SqlDbType.Int, 0, ParameterDirection.Input, Id);

            SetCommandType(command, CommandType.StoredProcedure, StoreProcedureName.Sp_Sitesettings_DeleteOne.ToString());

            int returnValue = (int)GetOneData(command);
            return (returnValue == 0 ? false : true);
        }

        /// <summary>
        /// Static selection method. Used for loading a perticular data using primary key id.
        /// </summary>
        /// <param name="id">Primary key</param>
        /// <returns>Instance of the loaded object</returns>
        [System.ComponentModel.DataObjectMethodAttribute(System.ComponentModel.DataObjectMethodType.Select, true)]
        public static Sitesettings Load(int id)
        {
            Sitesettings sitesettings = new Sitesettings();
            sitesettings.Id = id;

            if (sitesettings.Load())
                return sitesettings;
            else
                return null;
        }

        /// <summary>
        /// Instance selection method that fetches data using paging and sorting and also with 
        /// custom conditions.
        /// </summary>
        /// <param name="oderBy">Sorting order</param>
        /// <param name="startRow">Page start position</param>
        /// <param name="pageSize">Number of maximum record to be shown</param>
        /// <param name="conditions">Custom condition based on which to match data</param>
        /// <returns>List of instances of loaded objects</returns>
        public List<Sitesettings> Load(string orderBy, int startRow, int pageSize, List<Condition> conditions)
        {
            List<Sitesettings> sitesettingss = new List<Sitesettings>();
			
			SqlCommand command = (SqlCommand)CreateCommand();
			
            PrepareConditionalParameters(command, conditions);

            AddCommandParameter(command, "@ReturnValue", SqlDbType.Int, 0, ParameterDirection.ReturnValue, null);
            AddCommandParameter(command, "@OrderBy", SqlDbType.NVarChar, 50, ParameterDirection.Input, orderBy);
            AddCommandParameter(command, "@StartRow", SqlDbType.Int, 0, ParameterDirection.Input, startRow);
            AddCommandParameter(command, "@PageSize", SqlDbType.Int, 0, ParameterDirection.Input, pageSize);

            SetCommandType(command, CommandType.StoredProcedure, StoreProcedureName.Sp_Sitesettings_LoadConditionalPaged.ToString());

            List<BaseDAO> dataList = GetListData(command);

            foreach (BaseDAO data in dataList)
            {
                Sitesettings sitesettings = (Sitesettings)data;
                sitesettingss.Add(sitesettings);
            }

            return sitesettingss;
        }

        /// <summary>
        /// Counts the number of total record available
        /// </summary>
        /// <param name="conditions">Custom condition based on which to match data</param>
        /// <returns>Count of the records</returns>
        public int LoadCount(List<Condition> conditions)
        {
			SqlCommand command = (SqlCommand)CreateCommand();
			
            PrepareConditionalParameters(command, conditions);

            AddCommandParameter(command, "@ReturnValue", SqlDbType.Int, 0, ParameterDirection.ReturnValue, null);
            SetCommandType(command, CommandType.StoredProcedure, StoreProcedureName.Sp_Sitesettings_LoadConditionalPagedCount.ToString());

            int returnValue = (int)GetOneData(command);
            return returnValue;
        }

        /// <summary>
        /// Instance selection method that fetches data using paging and sorting.
        /// </summary>
        /// <param name="oderBy">Sorting order</param>
        /// <param name="startRow">Page start position</param>
        /// <param name="pageSize">Number of maximum record to be shown</param>
        /// <returns>List of instances of loaded objects</returns>
        public List<Sitesettings> Load(string orderBy, int startRow, int pageSize)
        {
            List<Sitesettings> sitesettingss = new List<Sitesettings>();
            
			SqlCommand command = (SqlCommand)CreateCommand();
			
            AddCommandParameter(command, "@ReturnValue", SqlDbType.Int, 0, ParameterDirection.ReturnValue, null);
            AddCommandParameter(command, "@OrderBy", SqlDbType.NVarChar, 50, ParameterDirection.Input, orderBy);
            AddCommandParameter(command, "@StartRow", SqlDbType.Int, 0, ParameterDirection.Input, startRow);
            AddCommandParameter(command, "@PageSize", SqlDbType.Int, 0, ParameterDirection.Input, pageSize);

            SetCommandType(command, CommandType.StoredProcedure, StoreProcedureName.Sp_Sitesettings_LoadPaged.ToString());

            List<BaseDAO> dataList = GetListData(command);

            foreach (BaseDAO data in dataList)
            {
                Sitesettings sitesettings = (Sitesettings)data;
                sitesettingss.Add(sitesettings);
            }

            return sitesettingss;
        }

        /// <summary>
        /// Counts the number of total record available
        /// </summary>
        /// <returns>Count of the records</returns>
        public int LoadCount()
        {
			SqlCommand command = (SqlCommand)CreateCommand();
			
            AddCommandParameter(command, "@ReturnValue", SqlDbType.Int, 0, ParameterDirection.ReturnValue, null);
            SetCommandType(command, CommandType.StoredProcedure, StoreProcedureName.Sp_Sitesettings_LoadPagedCount.ToString());

            int returnValue = (int)GetOneData(command);
            return returnValue;
        }

        /// <summary>
        /// Instance selection method. Used for reloading the current object from table. This method uses
        /// the Id of the current object to load and expects that the Id is correct.
        /// </summary>
        /// <returns>Boolean result as success or failure</returns>
        public override bool Load()
        {
			SqlCommand command = (SqlCommand)CreateCommand();
			
            AddCommandParameter(command, "@ReturnValue", SqlDbType.Int, 0, ParameterDirection.ReturnValue, null);
            AddCommandParameter(command, "@Id", SqlDbType.Int, 0, ParameterDirection.Input, Id);

            SetCommandType(command, CommandType.StoredProcedure, StoreProcedureName.Sp_Sitesettings_Load.ToString());

            List<BaseDAO> dataList = GetListData(command);

            foreach (BaseDAO data in dataList)
            {
                Sitesettings sitesettings = (Sitesettings)data;

                this._id = sitesettings._id;
				this._settingName = sitesettings._settingName;
				this._adminEmail = sitesettings._adminEmail;
				this._securityKey = sitesettings._securityKey;
				this._supportEmail = sitesettings._supportEmail;
				this._smtpHost = sitesettings._smtpHost;
				this._smtpUsername = sitesettings._smtpUsername;
				this._smtpPassword = sitesettings._smtpPassword;
				this._smtpPort = sitesettings._smtpPort;
				this._smtpUseSsl = sitesettings._smtpUseSsl;
				this._siteName = sitesettings._siteName;
				this._defaultTheme = sitesettings._defaultTheme;
				this._defaultTimeZone = sitesettings._defaultTimeZone;
				this._defaultUserroleId = sitesettings._defaultUserroleId;
				this._currentDomain = sitesettings._currentDomain;

                break;
            }

            return (dataList.Count > 0 ? true : false);
        }

        /// <summary>
        /// Instance selection method. Used for loading multiple record based on provided conditions.
        /// </summary>
        /// <param name="conditions">Custom condition based on which to match data</param>
        /// <returns>List of instances of loaded objects</returns>
        public List<Sitesettings> Load(List<Condition> conditions)
        {
            List<Sitesettings> sitesettingss = new List<Sitesettings>();

			SqlCommand command = (SqlCommand)CreateCommand();
			
            PrepareConditionalParameters(command, conditions);

            SetCommandType(command, CommandType.StoredProcedure, StoreProcedureName.Sp_Sitesettings_LoadConditional.ToString());

            List<BaseDAO> dataList = GetListData(command);

            foreach (BaseDAO data in dataList)
            {
                Sitesettings sitesettings = (Sitesettings)data;
                sitesettingss.Add(sitesettings);
            }

            return sitesettingss;
        }

        /// <summary>
        /// Prepares the conditional parameters for use with Create/ Save/ Load/ Delete methods
        /// that use custom condition. Prepares the user Command object for using conditions.
        /// </summary>
        /// <param name="conditions">Custom condition based on which to match data</param>
        private void PrepareConditionalParameters(SqlCommand command, List<Condition> conditions)
        {
            StringBuilder condition = new StringBuilder();

            object id = null;
			object settingName = null;
			object adminEmail = null;
			object securityKey = null;
			object supportEmail = null;
			object smtpHost = null;
			object smtpUsername = null;
			object smtpPassword = null;
			object smtpPort = null;
			object smtpUseSsl = null;
			object siteName = null;
			object defaultTheme = null;
			object defaultTimeZone = null;
			object defaultUserroleId = null;
			object currentDomain = null;

            for (int i = 0; i < conditions.Count; i++)
            {
                string fieldName = Utility.ToHungarianNotation(conditions[i].FieldName);

                if (conditions[i].JoiningCondition == JoinOperator.FirstValue)
                {
                    condition.Append("WHERE ");
                }
                else if (conditions[i].JoiningCondition == JoinOperator.And)
                {
                    condition.Append(" AND ");
                }
                else if (conditions[i].JoiningCondition == JoinOperator.Or)
                {
                    condition.Append(" OR ");
                }

                condition.Append(conditions[i].FieldName).Append(" ").Append(Condition.MapCondition(conditions[i].ConditionalOperator)).Append("@" + fieldName);

                if ((conditions[i].ConditionalOperator == ConditionOperator.Like ||
                    conditions[i].ConditionalOperator == ConditionOperator.NotLike))
                {
                    if (string.IsNullOrEmpty(conditions[i].Value.ToString()))
                        conditions[i].Value = "%%%";
                    else
                        conditions[i].Value = "%" + conditions[i].Value.ToString() + "%";
                }

                if (fieldName == TableColumns.Id.ToString())
                    id = conditions[i].Value;
                else if (fieldName == TableColumns.SettingName.ToString())
					settingName = conditions[i].Value;
				else if (fieldName == TableColumns.AdminEmail.ToString())
					adminEmail = conditions[i].Value;
				else if (fieldName == TableColumns.SecurityKey.ToString())
					securityKey = conditions[i].Value;
				else if (fieldName == TableColumns.SupportEmail.ToString())
					supportEmail = conditions[i].Value;
				else if (fieldName == TableColumns.SmtpHost.ToString())
					smtpHost = conditions[i].Value;
				else if (fieldName == TableColumns.SmtpUsername.ToString())
					smtpUsername = conditions[i].Value;
				else if (fieldName == TableColumns.SmtpPassword.ToString())
					smtpPassword = conditions[i].Value;
				else if (fieldName == TableColumns.SmtpPort.ToString())
					smtpPort = conditions[i].Value;
				else if (fieldName == TableColumns.SmtpUseSsl.ToString())
					smtpUseSsl = conditions[i].Value;
				else if (fieldName == TableColumns.SiteName.ToString())
					siteName = conditions[i].Value;
				else if (fieldName == TableColumns.DefaultTheme.ToString())
					defaultTheme = conditions[i].Value;
				else if (fieldName == TableColumns.DefaultTimeZone.ToString())
					defaultTimeZone = conditions[i].Value;
				else if (fieldName == TableColumns.DefaultUserroleId.ToString())
					defaultUserroleId = conditions[i].Value;
				else if (fieldName == TableColumns.CurrentDomain.ToString())
					currentDomain = conditions[i].Value;
            }

            AddCommandParameter(command, "@Condition", SqlDbType.NVarChar, 2000, ParameterDirection.Input, condition.ToString());
            AddCommandParameter(command, "@Id", SqlDbType.Int, 0, ParameterDirection.Input, id);
			AddCommandParameter(command, "@SettingName", SqlDbType.NVarChar, 50, ParameterDirection.Input, settingName);
			AddCommandParameter(command, "@AdminEmail", SqlDbType.NVarChar, 50, ParameterDirection.Input, adminEmail);
			AddCommandParameter(command, "@SecurityKey", SqlDbType.NVarChar, 50, ParameterDirection.Input, securityKey);
			AddCommandParameter(command, "@SupportEmail", SqlDbType.NVarChar, 50, ParameterDirection.Input, supportEmail);
			AddCommandParameter(command, "@SmtpHost", SqlDbType.NVarChar, 50, ParameterDirection.Input, smtpHost);
			AddCommandParameter(command, "@SmtpUsername", SqlDbType.NVarChar, 50, ParameterDirection.Input, smtpUsername);
			AddCommandParameter(command, "@SmtpPassword", SqlDbType.NVarChar, 50, ParameterDirection.Input, smtpPassword);
			AddCommandParameter(command, "@SmtpPort", SqlDbType.Int, 0, ParameterDirection.Input, smtpPort);
			AddCommandParameter(command, "@SmtpUseSsl", SqlDbType.Bit, 0, ParameterDirection.Input, smtpUseSsl);
			AddCommandParameter(command, "@SiteName", SqlDbType.NVarChar, 50, ParameterDirection.Input, siteName);
			AddCommandParameter(command, "@DefaultTheme", SqlDbType.NVarChar, 50, ParameterDirection.Input, defaultTheme);
			AddCommandParameter(command, "@DefaultTimeZone", SqlDbType.Int, 0, ParameterDirection.Input, defaultTimeZone);
			AddCommandParameter(command, "@DefaultUserroleId", SqlDbType.Int, 0, ParameterDirection.Input, defaultUserroleId);
			AddCommandParameter(command, "@CurrentDomain", SqlDbType.NVarChar, 50, ParameterDirection.Input, currentDomain);
        }

        /// <summary>
        /// Binds the fetched data from data reader to Objects
        /// </summary>
        /// <param name="reader">Data reader supplied by BaseDAO</param>
        /// <returns>List of object instances that was bound</returns>
        protected override List<BaseDAO> BindData(DbDataReader reader)
        {
            List<BaseDAO> result = new List<BaseDAO>();

			if (reader == null)
                return null;

            while (reader.Read())
            {
                Sitesettings sitesettings = new Sitesettings
                (
					reader["id"] == System.DBNull.Value ? GetIdMinValue : (int)reader["id"],
                    reader["setting_name"] == System.DBNull.Value ? string.Empty : (string)reader["setting_name"],
					reader["admin_email"] == System.DBNull.Value ? string.Empty : (string)reader["admin_email"],
					reader["security_key"] == System.DBNull.Value ? string.Empty : (string)reader["security_key"],
					reader["support_email"] == System.DBNull.Value ? string.Empty : (string)reader["support_email"],
					reader["smtp_host"] == System.DBNull.Value ? string.Empty : (string)reader["smtp_host"],
					reader["smtp_username"] == System.DBNull.Value ? string.Empty : (string)reader["smtp_username"],
					reader["smtp_password"] == System.DBNull.Value ? string.Empty : (string)reader["smtp_password"],
					reader["smtp_port"] == System.DBNull.Value ? 0 : (int)reader["smtp_port"],
					reader["smtp_use_ssl"] == System.DBNull.Value ? false : (bool)reader["smtp_use_ssl"],
					reader["site_name"] == System.DBNull.Value ? string.Empty : (string)reader["site_name"],
					reader["default_theme"] == System.DBNull.Value ? string.Empty : (string)reader["default_theme"],
					reader["default_time_zone"] == System.DBNull.Value ? 0 : (int)reader["default_time_zone"],
					reader["default_userrole_id"] == System.DBNull.Value ? 0 : (int)reader["default_userrole_id"],
					reader["current_domain"] == System.DBNull.Value ? string.Empty : (string)reader["current_domain"]
                );

                result.Add(sitesettings);
            }
            
            if(!reader.IsClosed)
                reader.Close();

            return result;
        }

        /// <summary>
        /// List of store procedures that this class use
        /// </summary>
        private enum StoreProcedureName
        {
            Sp_Sitesettings_Save = 0,
            Sp_Sitesettings_Create = 1,
            Sp_Sitesettings_DeleteOne = 2,
            Sp_Sitesettings_DeleteMultiple = 3,
            Sp_Sitesettings_DeleteConditional = 4,
            Sp_Sitesettings_SaveConditional = 5,
            Sp_Sitesettings_LoadConditional = 6,
            Sp_Sitesettings_Load = 7,
            Sp_Sitesettings_LoadConditionalPaged = 8,
            Sp_Sitesettings_LoadConditionalPagedCount = 9,
            Sp_Sitesettings_LoadPaged = 10,
            Sp_Sitesettings_LoadPagedCount = 11
        }

        /// <summary>
        /// List of table column names that this class use
        /// </summary>
        private enum TableColumns
        {
            Id = 0,
			SettingName = 1,
			AdminEmail = 2,
			SecurityKey = 3,
			SupportEmail = 4,
			SmtpHost = 5,
			SmtpUsername = 6,
			SmtpPassword = 7,
			SmtpPort = 8,
			SmtpUseSsl = 9,
			SiteName = 10,
			DefaultTheme = 11,
			DefaultTimeZone = 12,
			DefaultUserroleId = 13,
			CurrentDomain = 14
        }
    }
}